package com.atguigu.lock8;

import java.util.concurrent.TimeUnit;

/**
 * @Author 孔德成
 * @Slogan 致敬大师，致敬未来的你
 * @date 2021/8/7
 * @desc 新增普通hello方法，请问先打印邮件还是hello？
 */
public class Lock3Demo {

    public static void main(String[] args) throws InterruptedException {
        Phone phone1 = new Phone();
        new Thread(phone1::sendEmail, "t1").start();
        TimeUnit.MILLISECONDS.sleep(100);
        new Thread(phone1::hello, "t2").start();
    }

    private static class Phone {
        /**
         * 普通同步方法
         */
        public synchronized void sendEmail() {
            try {
                TimeUnit.SECONDS.sleep(4);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("-----Email");

        }

        public synchronized void sendSMS() {
            System.out.println("-----SMS");
        }

        public void hello() {
            System.out.println("-----hello");
        }

    }

}

